package com.yf.zzmusic.pojo.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotNull;

/**
 * <p>
 * 收藏数表。用于存储音乐、歌单和专辑的收藏数
 * </p>
 *
 * @author
 * @since 2024-03-19
 */
@Getter
@Setter
@TableName("favorite_count")
public class FavoriteCount implements Serializable {

  private static final long serialVersionUID = 1L;

  /**
   * 收藏id
   */
  @TableId(value = "favorite_count_id", type = IdType.AUTO)
  private Integer favoriteCountId;

  /**
   * 1表示歌单，2表示专辑
   */
  @NotNull(message = "目标类型(type)不可为空")
  private Integer type;

  /**
   * 目标id，其id必须是music 歌单 专辑中的一种
   */
  @NotNull(message = "目标id(targetId)不可为空")
  private Integer targetId;

  /**
   * 用户id
   */
  @NotNull(message = "用户id(userId)不可为空")
  private Integer userId;

  @DateTimeFormat(pattern = "yyyy-MM-dd")
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
  private LocalDateTime createTimer;

  public Long getCreateTimer() {
    if (createTimer!=null){
      long timestamp = createTimer.toInstant(ZoneOffset.of("+8")).toEpochMilli();
      return timestamp;
    }else {
      return null;
    }
  }

  public void setCreateTimer(LocalDateTime createTimer) {
    this.createTimer = createTimer;
  }

}
